package day25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 题目：数根
 * 题目链接：https://www.nowcoder.com/questionTerminal/e2422543519249f292d8435394ab82fe
 */
public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = reader.readLine()) != null) {
            char[] chars = line.toCharArray();
            int ret = 0;
            do {
                ret = 0;
                for (int i = 0; i < chars.length; i++) {
                    ret += Integer.parseInt(String.valueOf(chars[i]));
                }
                line = String.valueOf(ret);
                chars = line.toCharArray();
            } while (ret >= 10);
            System.out.println(ret);
        }
    }
}
